home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- # program to check /etc/hosts vs. named.hosts
- #
- # Eric Murray 12/29/93
- # ericm@microunity.com
-
-
- sub usage {
- print "usage: $0 [-h hosts file] [-n named.hosts file]\n";
- exit 1;
- }
-
- $hosts = "/etc/hosts";
- $named = "/etc/named.d/named.hosts";
-
- while ($ARGV[0]) {
- if ($ARGV[0] =~ /^-h/) { shift; $hosts = $ARGV[0]; }
- elsif ($ARGV[0] =~ /^-n/) { shift; $named = $ARGV[0]; }
- elsif ($ARGV[0] =~ /^-i/) { $iponly++; }
- shift;
- }
-
- open(FH,"$hosts") || die "can't open $hosts: $!\n";
- while(<FH>) {
- chop;
- s/#.*$//;
- next if (/^$/);
- local($ip,$name) = split;
- $hostnames{$ip} = $name;
- $hostips{$name} = $ip if !defined $iponly;
- }
- close(FH);
-
- open(FH,"$named") || die "can't open $named: $!\n";
- while(<FH>) {
- chop;
- s/;.*$//;
- next if (/^$/);
- next if ($_ !~ /\s+A\s+\d+/); # skip all but A records
- local($name,$a,$ip) = split;
- $dnsnames{$ip} = $name;
- $dnsips{$name} = $ip if !defined $iponly;
- }
- close(<FH>);
-
- # now compare & contrast:
-
- print "checking $hosts vs. $named:\n";
- foreach $ip (sort(keys %hostnames)) {
- if (!defined $dnsnames{$ip}) {
- if (! defined $dnsips{$hostnames{$ip}}) {
- print "$hostnames{$ip} ($ip) in $hosts but not in $named\n"; $bad++;
- }
- else {
- print "IP addr mis-match for $hostnames{$ip}: $hosts says \"$ip\", $named says \"$dnsips{$hostnames{$ip}}\"\n";$bad++;
- }
- }
- elsif ($dnsnames{$ip} ne $hostnames{$ip}) {
- print "hostname mis-match for $ip: hosts says \"$hostnames{$ip}\", $named says \"$dnsnames{$ip}\"\n";$bad++;
- #undef $dnsnames{$ip}; undef $hostnames{$ip};
- }
- }
-
- print "checking $named vs. $hosts:\n";
- foreach $host (sort(keys %dnsips)) {
- if (! defined $hostips{$host}) {
- print "$host in $named but not in $hosts\n"; $bad++;
- }
- }
-
- exit $bad;
-